package edu.gmu;

import java.util.ArrayList;
import java.util.List;

/**
 * Tag defines the types that a Token can have.
 *
 * @author  James H. Pope
 * @version $Revision:$ $Date:$
 */
public class Id
{
//    jamess-macbook-pro:Minidl james$ java -cp ./dist/minidl.jar IDLParser Event.idl
//    IDL Parser Version 0.1:  Reading from file Event.idl . . .
//      specification
//        definition
//          module
//            identifier
//            definition
//              interfacex
//                interface_dcl
//                  interface_header
//                    identifier
//                  interface_body
//                    export
//                      attr_dcl
//                        param_type_spec
//                          scoped_name
//                            identifier
//                        simple_declarator
//                          identifier
//                    export
//                      attr_dcl
//                        param_type_spec
//                          string_type
//                        simple_declarator
//                          identifier
//    IDL Parser Version 0.1:  IDL definitions parsed successfully.
    /**
     * List of enums
     */
    public static final List LIST = new ArrayList();


    public static final Id SPECIFICATION  = new Id(  0, "SPECIFICATION" );
    public static final Id DEFINITION     = new Id(  1, "DEFINITION" );
    public static final Id MODULE         = new Id(  2, "MODULE" );
    public static final Id IDENTIFIER     = new Id(  3, "IDENTIFIER" );
    public static final Id INTERFACEX     = new Id(  4, "INTERFACEX" );
    public static final Id INTERFACE_DECL = new Id(  5, "INTERFACE_DECL" );
    public static final Id EXPORT         = new Id(  6, "EXPORT" );
    public static final Id ATTR_DECL      = new Id(  7, "ATTR_DECL" );
    public static final Id PARAM_TYPE_SPEC= new Id(  8, "PARAM_TYPE_SPEC" );

    public static final Id SCOPED_NAME    = new Id(  9, "SCOPED_NAME" );

    public static final Id SIMPLE_DECLARATOR  = new Id( 11, "SIMPLE_DECLARATOR" );
    public static final Id STRING_TYPE    = new Id( 12, "STRING_TYPE" );

    // Instance variables
    private int    id   = 0;
    private String name = null;



    /**
     * Creates a new Tag with specified values.
     * @param id
     * @param name
     */
    public Id(int id, String name)
    {
        this.id     = id;
        this.name   = name;

        LIST.add( this );
    }

    /**
     * Gets id.
     * @return id
     */
    public int getId()
    {
        return this.id;
    }

    /**
     * Gets name.
     * @return name
     */
    public String getName()
    {
        return this.name;
    }


    /**
     * Gets enum from given id
     * @param id of enum to get
     * @return enum of given id or null if not found
     */
    public static Id get( int id )
    {
        Id enumeration = null;
        for( int i = 0; i < LIST.size(); i++ )
        {
            Id aEnumeration = (Id)LIST.get(i);
            if( aEnumeration.getId() == id )
            {
                enumeration = aEnumeration;
                break;
            }
        }
        return enumeration;
    }

    /**
     * Gets enum from given name
     * @param name of enum to get
     * @return enum of given name or null if not found
     */
    public static Id get( String name )
    {
        Id enumeration = null;
        for( int i = 0; i < LIST.size(); i++ )
        {
            Id aEnumeration = (Id)LIST.get(i);
            if( aEnumeration.getName().equalsIgnoreCase(name) )
            {
                enumeration = aEnumeration;
                break;
            }
        }
        return enumeration;
    }


    /**
     * Gets this String facsimile of this object.
     * @return name
     */
    public String toString( )
    {
        return this.name;
    }
}
